# ser/number_service.py

import rclpy
from rclpy.node import Node
from example_interfaces.srv import AddThreeInts
import numpy as np

class NumberProcessor:
    def __init__(self):
        self.numbers = np.array([])

    def setNumbers(self, numbers):
        self.numbers = np.array(numbers)

    def getSum(self):
        return np.sum(self.numbers)

    def getProduct(self):
        return np.prod(self.numbers)

class NumberService(Node):
    def __init__(self):
        super().__init__('number_service')
        self.srv = self.create_service(AddThreeInts, 'process_numbers', self.process_numbers_callback)

    def process_numbers_callback(self, request, response):
        numbers = [request.a, request.b, request.c]
        processor = NumberProcessor()
        processor.setNumbers(numbers)
        if request.operation == 'add':
            response.sum = processor.getSum()
        elif request.operation == 'multiply':
            response.sum = processor.getProduct()
        else:
            response.sum = 0.0
        return response

def main(args=None):
    rclpy.init(args=args)
    number_service = NumberService()
    rclpy.spin(number_service)
    number_service.destroy_node()
    rclpy.shutdown()

if __name__ == '__main__':
    main()
